package cn.itcast.aanocationAop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author: cuisensen
 * data: 2018/6/13.
 * time: 22:01.
 */
@Aspect
public class MyAdvice {
    @Pointcut("execution(* cn.itcast.aanocationAop.*ServiceImp.*(..))")
    public void pc(){}
    @Before("MyAdvice.pc()")
    public void before(){
        System.out.println("前置通知");
    }
    @After("MyAdvice.pc()")
    public void after(){
        System.out.println("后置通知(方法出异常也会执行)");
    }
    @AfterReturning("MyAdvice.pc()")
    public void afterReturning(){
        System.out.println("后置通知(正常结束)");
    }
    @Around("MyAdvice.pc()")
    public Object round(ProceedingJoinPoint pj) throws Throwable {
        System.out.println("前置前置");
        Object proceed = pj.proceed();
        System.out.println("后置后置");
        return proceed;
    }
    @AfterThrowing("MyAdvice.pc()")
    public void afterException(){
        System.out.println("出事啦");
    }
}
